\documentclass[border=10pt,tikz]{standalone}
\usepackage{pgfplots,pgfplotstable,tikz}
\usetikzlibrary{intersections}
\usepackage{verbatim}
\usepackage{moresize}
\usetikzlibrary{calc}
\usepackage{datatool}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{xspace} 
\usepackage{etoolbox}
\usepackage{multirow}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\pgfplotsset{compat=1.13}
\usepackage{fp}


\definecolor{green}{RGB}{68,126,35}
\definecolor{blue}{RGB}{19,30,92}
\definecolor{red}{RGB}{219,51,24}

% Defines "sgn" function
\def\sgn{\mathop{\rm sgn}\nolimits} 
% Defines the expectation function
\def\E{\mathop{\mathrm{E}}\nolimits} 

% Defines a function that ignores the zero on the y- or the x-axis, such that the origin
% is only labeled once. Activate in the axis options by adding the key: "ignore zero=x" or ""ignore zero=y."
\pgfplotsset{ignore zero/.style={%
		#1ticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi}
	}}

\pgfkeys{/pgf/number format/.cd, fixed, precision=2} %set precision of the printed numbers


\begin{document}
% TAKE INPUTS FROM THE FOLLOWING FILE: "linmte_no_covars_Y_num_oregonnumhh1.csv" --- generated in Stata by the program file: "linmte_no_covars_graph_data.do"
\begingroup\catcode`"=9 % ignore quotation marks in csv file
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{2}]{linmte_no_covars_Y_num_oregonnumhh1.csv}{}{
	% Enforce display of decimal points
	\pgfkeys{/pgf/number format/fixed zerofill=true}
	
	% Store Labels
	\newcommand*{\D}{\Dlab\xspace}
	\newcommand*{\Y}{\Ylab\xspace}


	% [yaxismin, yaxismax, yaxislength] Calculate graphing region for the y-axis
	\pgfmathsetmacro\yaxismin{0}
	\pgfmathsetmacro\yaxismax{\BTTO*1.13}
	\pgfmathsetmacro\yaxislength{\yaxismax-\yaxismin}
	


	
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}[>=stealth]
\tikzset{
	every pin/.style={black},
	%every pin edge/.style={draw=black}
}

% Axis options
\begin{axis}[					
	width=15cm,					% width of chart
	height=10cm,				% height of chart
	xlabel={$U_D$:  unobserved net cost of treatment},				% x-axis title
	ylabel={\Y},					% y-axis title
	ylabel style={rotate=0},  % rotate the y-axis title
	samples=100,  				% sets the resolution for curved lines
	xmin=0,xmax=1,			    % x-axis range
	ymin=\yaxismin,
	%ymin=1.2*\Dinterceptr,ymax=1.05*\yaxismax,			% y-axis range
	ignore zero=y,			    % ignore the zero on the y-axis (defined in preamble)
	xtick={0,\pB,\pI,1},	    % only show these x ticks
	xticklabels={0,$p_C=\pgfmathprintnumber{\pB}$, $p_I=\pgfmathprintnumber{\pI}$,1}, % label x ticks
	ytick={0,\IUUO, \BUUO, \LAUO, \LATO, \ITTO, \BTTO},	    % only show these y ticks
	ymax = \yaxismax,
	legend style={
		draw=none,
		at={(1,1)},
		anchor=north east,
		fill=none
	},	% set legend style, specifically no outline
	legend cell align={left},	% align legend content to the left
	clip=false,					% place nodes outside of plot area
			xticklabel style={
									yshift=-5.5ex,
									name=label,
									append after command={(label.north) edge [solid] ++(0,6ex)},
									/pgf/number format/fixed,
									/pgf/number format/precision=2},
								x label style={at={(axis description cs:0.5,-0.15)},anchor=north}, % ncrease distance between title and x-axis
								yticklabel style={/pgf/number format/fixed},
								% place some extra y ticks ...
								extra y ticks={0},
								% ... but do not repeat the already existent labels
								% (from the "normal" ticks) ...
								extra y tick labels={0},
								% ... and set the style of the extra ticks to `major'
								extra tick style={
									grid=major,
								},
	]		
	


	% E[Y|D=1,Z=1]
	\addplot[
		line width=2.2pt, line cap=round, green, dashed, dash pattern=on 0.6pt off 3.5pt
	] coordinates {(0,\ITTO) (\pI,\ITTO)};	% plots a straight line between these coordinates
	
	% E[Y|D=0,Z=0]
	\addplot[
		line width=1.8pt, blue, dashed, dash pattern=on 3.8pt off 2pt
	] coordinates {(\pB,\BUUO) (1,\BUUO)};

	% LATO
	\addplot[
		line width=2.2pt, line cap=round, black!20!green, dashed, dash pattern=on 0.6pt off 3.5pt, opacity=0.4
	] coordinates {(\pB,\LATO) (\pI,\LATO)};

	% LAUO
	\addplot[
		line width=1.8pt, black!20!blue, dashed, dash pattern=on 3.8pt off 2pt, opacity=0.4
	] coordinates {(\pB,\LAUO) (\pI,\LAUO)};

	% IUUO
	\addplot[
		line width=1.8pt, blue, dashed, dash pattern=on 3.8pt off 2pt
	] coordinates {(\pI,\IUUO) (1,\IUUO)};
	
	% BTTO
	\addplot[
		line width=2.2pt, line cap=round, green, dashed, dash pattern=on 0.6pt off 3.5pt
	] coordinates {(0,\BTTO) (\pB,\BTTO)};

	
	%Put equations on graph
	
	%Treated compliers
	\node[color = green, anchor=west] at (0.44, \LATO) {$\pgfmathprintnumber{\LATO}=${\large $\frac{(\pgfmathprintnumber{\pI}*\pgfmathprintnumber{\ITTO} - \pgfmathprintnumber{\pB}*\pgfmathprintnumber{\BTTO})}{(\pgfmathprintnumber{\pI} -\pgfmathprintnumber{\pB})}$}};
	
	%Untreated compliers
	\node[color = blue, anchor=west] at (0.44, \LAUO) {$\pgfmathprintnumber{\LAUO}=${\large $\frac{((1-\pgfmathprintnumber{\pB})*\pgfmathprintnumber{\BUUO} - (1-\pgfmathprintnumber{\pI})*\pgfmathprintnumber{\IUUO})}{(\pgfmathprintnumber{\pI} -\pgfmathprintnumber{\pB})}$}};
	
	% add legend
	\legend{treated,untreated,,,,}
	
			% Put Always Takers, Compliers, and Never Takers on the x-axis
			\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (0,\yaxismin) -- (\pB, \yaxismin) node[pos=0.5, below, yshift = 0pt, align=left] {Always \\ Takers};
			\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (\pB,\yaxismin) -- (\pI, \yaxismin) node[pos=0.5, below, yshift = 0pt] {Compliers};
			\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (\pI,\yaxismin) -- (1, \yaxismin) node[pos=0.5, below, yshift = 0pt] {Never Takers};

	

\end{axis}
\end{tikzpicture}

	
}
\end{document}